﻿package mortal.game.net.command.battle
{
    import Framework.MQ.*;
    import Message.Command.*;
    import Message.Public.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.net.broadCast.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.mvc.core.*;

    public class BattleCommand extends BroadCastCall
    {

        public function BattleCommand(param1:Object)
        {
            super(param1);
            return;
        }// end function

        override public function call(param1:MessageBlock) : void
        {
            var _loc_2:SBattleApply = null;
            var _loc_3:SBattleReply = null;
            var _loc_4:SBattleStart = null;
            var _loc_5:SBattleResult = null;
            var _loc_6:SPublicEntityPair = null;
            super.call(param1);
            switch(param1.messageHead.command)
            {
                case EPublicCommand._ECmdPublicBattleApply:
                {
                    _loc_2 = param1.messageBase as SBattleApply;
                    NetDispatcher.dispatchCmd(ServerCommand.BattleApply, _loc_2);
                    break;
                }
                case EPublicCommand._ECmdPublicBattleReply:
                {
                    _loc_3 = param1.messageBase as SBattleReply;
                    NetDispatcher.dispatchCmd(ServerCommand.BattleReply, _loc_3);
                    break;
                }
                case EPublicCommand._ECmdPublicBattleStart:
                {
                    _loc_4 = param1.messageBase as SBattleStart;
                    NetDispatcher.dispatchCmd(ServerCommand.BattleStart, _loc_4);
                    break;
                }
                case EPublicCommand._ECmdPublicBattleResult:
                {
                    _loc_5 = param1.messageBase as SBattleResult;
                    Cache.instance.publicCache.battleEnemy = null;
                    NetDispatcher.dispatchCmd(ServerCommand.BattleResult, _loc_5);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityToEntityUpdate:
                {
                    _loc_6 = param1.messageBase as SPublicEntityPair;
                    if (EntityUtil.equal(_loc_6.fromEntity, Cache.instance.role.entityInfo.entityId))
                    {
                        Cache.instance.publicCache.battleEnemy = _loc_6.toEntity;
                    }
                    else if (EntityUtil.equal(_loc_6.toEntity, Cache.instance.role.entityInfo.entityId))
                    {
                        Cache.instance.publicCache.battleEnemy = _loc_6.fromEntity;
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
